import mysql from 'mysql';
//创建连接池
export const pool = mysql.createPool({
	host: 'localhost', //服务器地址
	user: 'root', //账号
	password: 'sq1yzawn', //密码
	database: 'tool_db' //数据库名称
});

//封装sql执行函数
export const executeQuery = (sql, values) => {
	return new Promise((resolve, reject) => {
		pool.getConnection((err, connection) => {
			if (err) {
				reject(err);
				return;
			}
			connection.query(
				sql,
				values,
				(queryErr, results) => {
					connection.release();

					if (queryErr) {
						reject(queryErr);
					} else {
						resolve(results);
					}
				}
			);
		});
	});
};
